package com.smallkingson.ylib.core.utils;


import android.annotation.SuppressLint;
import android.content.Intent;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;

import com.smallkingson.ylib.R;

public final class YFragments {

	public static void add(FragmentActivity activity, int container, Fragment fragment) {

		activity.getSupportFragmentManager().beginTransaction().add(container, fragment).commit();
	}

	public static void remove(FragmentActivity activity, Fragment fragment) {

		activity.getSupportFragmentManager().beginTransaction().remove(fragment).commit();
	}

	public static void replace(FragmentActivity activity, int container, Fragment fragment) {

		activity.getSupportFragmentManager().beginTransaction().replace(container, fragment).commit();
	}

	public static void replaceAndAddToStack(FragmentActivity activity, int container, Fragment fragment) {

		FragmentTransaction ft = activity.getSupportFragmentManager().beginTransaction();

		// ft.setCustomAnimations(R.anim.slide_in_left, R.anim.slide_out_right);
		// ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
		ft.setCustomAnimations(R.anim.y_push_left_in, R.anim.y_push_left_out, R.anim.y_back_left_in, R.anim.y_back_right_out);
		ft.addToBackStack(Fragment.class.getSimpleName());
		ft.replace(container, fragment).commit();
	}

	public static void AddAndAddToStack(FragmentActivity activity, int container, Fragment fragment) {

		FragmentTransaction ft = activity.getSupportFragmentManager().beginTransaction();
		// ft.setCustomAnimations(R.anim.slide_in_left, R.anim.slide_out_right);
		// ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
		ft.setCustomAnimations(R.anim.y_push_left_in, R.anim.y_push_left_out, R.anim.y_back_left_in, R.anim.y_back_right_out);
		ft.addToBackStack(Fragment.class.getSimpleName());
		ft.add(container, fragment).commit();
	}

	// @SuppressLint("NewApi")
	// public static void replaceAndAddToStack(FragmentActivity activity, int
	// container, android.app.Fragment fragment) {
	//
	// android.app.FragmentTransaction ft =
	// activity.getFragmentManager().beginTransaction();
	//
	// ft.setCustomAnimations(R.anim.push_left_in, R.anim.push_left_in,
	// R.anim.back_left_in, R.anim.back_right_out);
	// // ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
	// ft.replace(container, fragment);
	// ft.addToBackStack(Fragment.class.getSimpleName()).commit();
	// }

	public static void hide(FragmentActivity activity, Fragment fragment) {

		activity.getSupportFragmentManager().beginTransaction().hide(fragment).commit();
	}

	public static void show(FragmentActivity activity, Fragment fragment) {

		activity.getSupportFragmentManager().beginTransaction().show(fragment).commit();
	}
}
